\hypertarget{group__pustowka__batt}{
\section{BATTERY Library}
\label{group__pustowka__batt}\index{BATTERY Library@{BATTERY Library}}
}


Interrupt Battery library for checking the state of the battery in NXBOT.  
\subsection*{Defines}
\begin{DoxyCompactItemize}
\item 
\#define \hyperlink{group__pustowka__batt_ga1a0d280534953662003acd91f20071c1}{BATT\_\-READ\_\-VOLT}~0
\begin{DoxyCompactList}\small\item\em constant definition for battery\_\-read \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__pustowka__batt_ga61262b004f6813b955f4d0b2d6553817}{BATT\_\-READ\_\-PERC}~1
\begin{DoxyCompactList}\small\item\em constant definition for battery\_\-read \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \hyperlink{group__pustowka__batt_gabfbbfb986d008991dbbe32035cbdcde6}{battery\_\-init} (void)
\begin{DoxyCompactList}\small\item\em Hardware initialization for the battery module. \item\end{DoxyCompactList}\item 
void \hyperlink{group__pustowka__batt_gabf908968d26d8f291a60846d6dd51251}{battery\_\-ledEnable} (unsigned char en)
\begin{DoxyCompactList}\small\item\em Function used to write the state of the battery-\/LED, located in the rear of NXBot. \item\end{DoxyCompactList}\item 
unsigned char \hyperlink{group__pustowka__batt_gaa4799455728e1873e05d8bbe460d03fc}{battery\_\-getState} (void)
\begin{DoxyCompactList}\small\item\em Reads the state of the battery, in \mbox{[}\%\mbox{]} units. \item\end{DoxyCompactList}\item 
unsigned int \hyperlink{group__pustowka__batt_gada2d7b272290fee99245113b1c134a20}{battery\_\-getVoltage} (void)
\begin{DoxyCompactList}\small\item\em Reads the state of the battery, in \mbox{[}V\mbox{]} units. \item\end{DoxyCompactList}\item 
unsigned int \hyperlink{group__pustowka__batt_gaec4ef3b620c24ee1c4ea58e26fe93cb3}{battery\_\-read} (unsigned char type)
\begin{DoxyCompactList}\small\item\em Read the state of the battery, wether voltage or percentage. \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Interrupt Battery library for checking the state of the battery in NXBOT. 
\begin{DoxyCode}
 #include <battery.h> 
\end{DoxyCode}
 This module uses the built-\/in ADC of the ATmega1281 microcontroller. The battery is connected to a voltage divider, in order to obtain permisible voltage values for the microcontroller pins. Thus, when using a 6V full-\/charged battery, the voltage divider equals 1/2. Using a 12V full-\/charged battery, the voltage divider equals 1/4. The pin used by the microcontroller is the BATT\_\-PIN, defined in battery.c. The ADC is used at {\bfseries 8 bit-\/resolution}, and the readings are {\bfseries interrupt-\/driven}. That means, the module updates constantly the battery state variable, only if the interrupts are active. Therefore, it is necessary to enable interrupts, for example via the {\itshape sei()\/} function. 

\subsection{Define Documentation}
\hypertarget{group__pustowka__batt_ga61262b004f6813b955f4d0b2d6553817}{
\index{pustowka\_\-batt@{pustowka\_\-batt}!BATT\_\-READ\_\-PERC@{BATT\_\-READ\_\-PERC}}
\index{BATT\_\-READ\_\-PERC@{BATT\_\-READ\_\-PERC}!pustowka_batt@{pustowka\_\-batt}}
\subsubsection[{BATT\_\-READ\_\-PERC}]{\setlength{\rightskip}{0pt plus 5cm}\#define BATT\_\-READ\_\-PERC~1}}
\label{group__pustowka__batt_ga61262b004f6813b955f4d0b2d6553817}


constant definition for battery\_\-read \begin{DoxySeeAlso}{See also}
\hyperlink{group__pustowka__batt_gaec4ef3b620c24ee1c4ea58e26fe93cb3}{battery\_\-read} 
\end{DoxySeeAlso}
\hypertarget{group__pustowka__batt_ga1a0d280534953662003acd91f20071c1}{
\index{pustowka\_\-batt@{pustowka\_\-batt}!BATT\_\-READ\_\-VOLT@{BATT\_\-READ\_\-VOLT}}
\index{BATT\_\-READ\_\-VOLT@{BATT\_\-READ\_\-VOLT}!pustowka_batt@{pustowka\_\-batt}}
\subsubsection[{BATT\_\-READ\_\-VOLT}]{\setlength{\rightskip}{0pt plus 5cm}\#define BATT\_\-READ\_\-VOLT~0}}
\label{group__pustowka__batt_ga1a0d280534953662003acd91f20071c1}


constant definition for battery\_\-read \begin{DoxySeeAlso}{See also}
\hyperlink{group__pustowka__batt_gaec4ef3b620c24ee1c4ea58e26fe93cb3}{battery\_\-read} 
\end{DoxySeeAlso}


\subsection{Function Documentation}
\hypertarget{group__pustowka__batt_gaa4799455728e1873e05d8bbe460d03fc}{
\index{pustowka\_\-batt@{pustowka\_\-batt}!battery\_\-getState@{battery\_\-getState}}
\index{battery\_\-getState@{battery\_\-getState}!pustowka_batt@{pustowka\_\-batt}}
\subsubsection[{battery\_\-getState}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char battery\_\-getState (void)}}
\label{group__pustowka__batt_gaa4799455728e1873e05d8bbe460d03fc}


Reads the state of the battery, in \mbox{[}\%\mbox{]} units. This function returns the last calculated value for the battery state. The calculation of the state value is done in the ISR, each time a reading is complete. That means, when the interrupts are not enabled, the reading will not be actual neither accurate.

\begin{DoxyReturn}{Returns}
The battery state, from 0 to 100. 
\end{DoxyReturn}
\hypertarget{group__pustowka__batt_gada2d7b272290fee99245113b1c134a20}{
\index{pustowka\_\-batt@{pustowka\_\-batt}!battery\_\-getVoltage@{battery\_\-getVoltage}}
\index{battery\_\-getVoltage@{battery\_\-getVoltage}!pustowka_batt@{pustowka\_\-batt}}
\subsubsection[{battery\_\-getVoltage}]{\setlength{\rightskip}{0pt plus 5cm}unsigned int battery\_\-getVoltage (void)}}
\label{group__pustowka__batt_gada2d7b272290fee99245113b1c134a20}


Reads the state of the battery, in \mbox{[}V\mbox{]} units. This function returns the last calculated value for the battery voltage. The calculation of the voltage is done in the ISR, each time a reading is complete. That means, when the interrupts are not enabled, the reading will not be actual neither accurate.

\begin{DoxyReturn}{Returns}
The battery voltage, from 0 to 600 (when using 6V battery), or to 1200 (when using 12V battery). 
\end{DoxyReturn}
\hypertarget{group__pustowka__batt_gabfbbfb986d008991dbbe32035cbdcde6}{
\index{pustowka\_\-batt@{pustowka\_\-batt}!battery\_\-init@{battery\_\-init}}
\index{battery\_\-init@{battery\_\-init}!pustowka_batt@{pustowka\_\-batt}}
\subsubsection[{battery\_\-init}]{\setlength{\rightskip}{0pt plus 5cm}void battery\_\-init (void)}}
\label{group__pustowka__batt_gabfbbfb986d008991dbbe32035cbdcde6}


Hardware initialization for the battery module. Configures the ADC, enabling channel ADC0. VREF is the supply voltage (expected 5V). \hypertarget{group__pustowka__batt_gabf908968d26d8f291a60846d6dd51251}{
\index{pustowka\_\-batt@{pustowka\_\-batt}!battery\_\-ledEnable@{battery\_\-ledEnable}}
\index{battery\_\-ledEnable@{battery\_\-ledEnable}!pustowka_batt@{pustowka\_\-batt}}
\subsubsection[{battery\_\-ledEnable}]{\setlength{\rightskip}{0pt plus 5cm}void battery\_\-ledEnable (unsigned char {\em en})}}
\label{group__pustowka__batt_gabf908968d26d8f291a60846d6dd51251}


Function used to write the state of the battery-\/LED, located in the rear of NXBot. CAUTION!: This function is only used for debugging purposes. The LED is automatically activated, if the battery is full-\/charged. If the battery charge is below some predefined limit (5,2V), the LED will be automatically deactivated.


\begin{DoxyParams}{Parameters}
\item[{\em en}]1 for enabling the LED, 0 for disabling. Instead of these values, use either ON or OFF constants, defined globally in Makefile. \end{DoxyParams}
\hypertarget{group__pustowka__batt_gaec4ef3b620c24ee1c4ea58e26fe93cb3}{
\index{pustowka\_\-batt@{pustowka\_\-batt}!battery\_\-read@{battery\_\-read}}
\index{battery\_\-read@{battery\_\-read}!pustowka_batt@{pustowka\_\-batt}}
\subsubsection[{battery\_\-read}]{\setlength{\rightskip}{0pt plus 5cm}unsigned int battery\_\-read (unsigned char {\em type})}}
\label{group__pustowka__batt_gaec4ef3b620c24ee1c4ea58e26fe93cb3}


Read the state of the battery, wether voltage or percentage. This function is the same as \hyperlink{group__pustowka__batt_gaa4799455728e1873e05d8bbe460d03fc}{battery\_\-getState()} or \hyperlink{group__pustowka__batt_gada2d7b272290fee99245113b1c134a20}{battery\_\-getVoltage()}, and is included for compatibility issues (each sensor module should have a \_\-read() function). \begin{DoxySeeAlso}{See also}
\hyperlink{group__pustowka__batt_gaa4799455728e1873e05d8bbe460d03fc}{battery\_\-getState} \hyperlink{group__pustowka__batt_gada2d7b272290fee99245113b1c134a20}{battery\_\-getVoltage}
\end{DoxySeeAlso}

\begin{DoxyParams}{Parameters}
\item[{\em type}]Defines which value will be returned. Use BATT\_\-READ\_\-VOLT or BATT\_\-READ\_\-PERC to obtain Voltage or Percent, respectively. \end{DoxyParams}
\begin{DoxyReturn}{Returns}
same as in \hyperlink{group__pustowka__batt_gaa4799455728e1873e05d8bbe460d03fc}{battery\_\-getState()} or \hyperlink{group__pustowka__batt_gada2d7b272290fee99245113b1c134a20}{battery\_\-getVoltage()} 
\end{DoxyReturn}
